package com.example.seakdreamandroid.whiteNoise;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.example.seakdreamandroid.MainActivity;
import com.example.seakdreamandroid.R;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

/*
杨锐涵 白噪音频道
 */
public class WhiteNoiseActivity extends AppCompatActivity {
    private TabLayout tabLayout;
    private ViewPager2 viewPager2;
    private ImageView imageView;
    private String CHANNEL;
    private String ISPLAY;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_white_noise);
        //获取布局文件中的控件对象
        getViews();
        //准备fragment数据源
        List<Fragment> fragments = setData();
        //实例化适配器
        WhiteNoiseFragmentAdapter whiteNoiseFragmentAdapter = new WhiteNoiseFragmentAdapter(
                fragments,this
        );


        //绑定适配器
        viewPager2.setAdapter(whiteNoiseFragmentAdapter);
        //设置纵向滑动
        viewPager2.setOrientation(viewPager2.ORIENTATION_HORIZONTAL);
        //关联Tablayout和ViwePager2
        TabLayoutMediator mediator = new TabLayoutMediator(
                tabLayout,
                viewPager2,
                new TabLayoutMediator.TabConfigurationStrategy() {
                    @Override
                    public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                        switch (position){
                            case 0:
                                tab.setText("自由组合");
                                break;
                            case 1:
                                tab.setText("官方推荐");
                                break;
                            case 2:
                                tab.setText("眠友创作");
                                break;

                        }
                    }
                }
        );
        mediator.attach();
        imageView = findViewById(R.id.white_return);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(WhiteNoiseActivity.this, MainActivity.class);
                startActivity(intent);
            }
        });


    }
    //绑定数据
    private List<Fragment> setData() {
        List<Fragment> fragments = new ArrayList<>();
//        fragments.add(new FreeConbination(this));
//        fragments.add(new OfficialRecommendation(this));

        fragments.add(new FreeConbination(this));
        fragments.add(new OfficialRecommendation(this));
        fragments.add(new SleepFriendCreation(this));
        return fragments;
    }

    //获取布局文件中的控件对象
    private void getViews() {
        tabLayout = findViewById(R.id.white_tablayout);
        viewPager2 = findViewById(R.id.white_vp2);
    }

}